import { Component, OnInit, ViewChild } from '@angular/core';
import { _HttpClient } from '@delon/theme';
import { STColumn, STComponent, STChange, STPage } from '@delon/abc/table';
import { SFSchema, SFComponent, SFRadioWidgetSchema } from '@delon/form';
import { HttpService, SupDic, GridComponent } from 'lbf';
import { ActivatedRoute } from '@angular/router';
import { ReuseTabService } from '@delon/abc/reuse-tab';
import { LbStepsComponent } from '@shared/components/lb-steps/lb-steps.component';
import { LbWjfwComponent } from '@shared/components/lb_wjfw/lbwjfw.component';
import { LbRepComponent } from '@shared/components/lb-rep/lb-rep.component';
import { NzMessageService, NzModalService } from 'ng-zorro-antd';

@Component({
  selector: 'app-sybx-sysh',
  templateUrl: './sysh.component.html',
})
export class SybxSyshComponent implements OnInit {
  params = { sname: 'ShFf_QUERY', form: {} };

  tabs = ['办件信息', '材料影像'];
  dataset = [];
  PROJID = '1';
  DAD068 = '';
  DAD069 = '';
  DAD017 = ''; //事项编码
  AAE000 = '';
  AIC200 = '';
  isVisible = false;
  isOkLoading = false;
  constructor(
    private lbservice: HttpService,
    public msgSrv: NzMessageService,
    private supDic: SupDic,
    private reuseTabService: ReuseTabService,
    private activateroute: ActivatedRoute,
    private modalService: NzModalService,
  ) {
    this.reuseTabService.title = '生育待遇审核';
  }

  tabMode = 'bjxx';
  @ViewChild('sf', { static: false }) sf: SFComponent;
  @ViewChild('slxx', { static: false }) slxx: SFComponent;
  @ViewChild('st', { static: false }) st: GridComponent;
  @ViewChild('wjfw', { static: false }) wjfw: LbWjfwComponent;
  @ViewChild('step', { static: true }) step: LbStepsComponent;

  clsmcolumns: STColumn[] = [
    { title: '序号', index: 'RN', width: '10%' },
    { title: '材料名称', index: 'STUFFNAME', width: '50%' },
    {
      title: '操作区',
      buttons: [
        {
          text: '打开',
          click: (record: any) => this.open(record),
        },
      ],
    },
    /*{ title: '材料数量', index: 'STUFFNUM', width: '25%' },
    
    { title: '收件类型', index: 'STUFFTYPE', width: '15%' },*/
  ];

  //发放信息
  columns: STColumn[] = [
    { title: '待遇编码', index: 'AAA036' },
    { title: '开始年月', index: 'AAE310' },
    { title: '结束年月', index: 'AAE311' },
    { title: '结算方式', index: 'AAE163', dic: 'AAE163' },
    { title: '待遇金额', index: 'AAE019' },
    { title: '备注 ', index: 'AAE013' },
  ];

  page: STPage = {
    show: false,
  };

  slSchema: SFSchema = {
    properties: {
      DAD095: {
        type: 'string',
        title: '',
        enum: [
          { label: '审核通过', value: '1' },
          { label: '审核不通过', value: '0' },
        ],
        // tslint:disable-next-line: no-object-literal-type-assertion
        ui: {
          widget: 'radio',
          change: console.log,
          grid: {
            span: 24,
          },
        } as SFRadioWidgetSchema,
        default: '1',
      },
      DAD098: {
        type: 'string',
        title: '不予通过原因',
        ui: {
          visibleIf: { DAD095: ['0'] },
          spanLabelFixed: 80,
          grid: { span: 24 },
        },
      },
    },
    ui: { grid: { span: 24 } },
  };
  //待遇信息
  DySchema: SFSchema = {
    properties: {
      AAA027: {
        type: 'string',
        title: '统筹区',
        enum: this.supDic.getSFDic('AAB301'),
        ui: {
          widget: 'select',
        },
      },
      AAC002: {
        type: 'string',
        title: '社会保障号',
      },
      AAC003: {
        type: 'string',
        title: '姓名',
      },
      AAC004: {
        type: 'string',
        title: '性别',
        enum: this.supDic.getSFDic('AAC004'),
        ui: {
          widget: 'select',
        },
      },
      AAB001: {
        type: 'string',
        title: '单位编号',
      },
      AAB004: {
        type: 'string',
        title: '单位名称',
      },
      AAE140: {
        type: 'string',
        title: '险种',
        enum: this.supDic.getSFDic('AAE140'),
        ui: {
          widget: 'select',
        },
      },
      AMC028: {
        type: 'string',
        title: '胎儿数',
      },

      AMC011: {
        type: 'number',
        title: '津贴基数',
      },
      AMC002: {
        type: 'string',
        title: '生育类别',
        enum: this.supDic.getSFDic('AMC002'),
        ui: {
          widget: 'select',
        },
      },

      AMC032: {
        type: 'string',
        title: '产假天数',
      },

      AMC020: {
        type: 'string',
        title: '生育时间',
      },
      AKB020: {
        type: 'string',
        title: '医疗机构编码',
        ui: {
          grid: { span: 8 },
        },
      },
      AKB021: {
        type: 'string',
        title: '医疗机构名称',
        ui: {
          grid: { span: 8 },
        },
      },
      AKC201: {
        type: 'string',
        title: '医疗机构类型',
        enum: this.supDic.getSFDic('AKC201'),
        ui: {
          widget: 'select',
          grid: { span: 8 },
        },
      },
      AMC042: {
        type: 'string',
        title: '未就业配偶身份',
        ui: {
          grid: { span: 8 },
        },
      },

      AMC010: {
        type: 'string',
        title: '未就业配偶姓名',
        ui: {
          grid: { span: 8 },
        },
      },

      AMC041: {
        type: 'string',
        title: '医疗总金额',
        ui: {
          grid: { span: 8 },
        },
      },
      AMC038: {
        type: 'number',
        title: '医疗剔除金额',
        ui: {
          grid: { span: 8 },
        },
      },
      AIC160: {
        type: 'string',
        title: '首次支付年月',
        ui: {
          grid: { span: 8 },
        },
      },
      AAE145: {
        type: 'string',
        title: '支付途径',
        enum: this.supDic.getSFDic('AAE145'),
        ui: {
          widget: 'select',
          grid: { span: 8 },
        },
      },
      NAMECN: {
        type: 'string',
        title: '发放银行',
        ui: {
          grid: { span: 8 },
        },
      },
      WDMC: {
        type: 'string',
        title: '银行网点',
        ui: {
          grid: { span: 8 },
        },
      },
      AAE009: {
        type: 'string',
        title: '银行开户名称',
        ui: {
          grid: { span: 8 },
        },
      },
      AAE010: {
        type: 'string',
        title: '银行帐号',
        ui: {
          grid: { span: 8 },
        },
      },
      AAE013: {
        type: 'string',
        title: '备注',
        ui: {
          grid: { span: 8 },
        },
      },
      AIC200: {
        type: 'string',
        title: '待遇档案号',
        ui: {
          grid: { span: 8 },
        },
      },
      AAE000: {
        type: 'string',
        title: '系统业务号',
        ui: {
          grid: { span: 8 },
        },
      },
    },
    ui: {
      spanLabelFixed: 100,
      grid: { span: 6 },
    },
  };

  ngOnInit() {
    if (this.activateroute.snapshot.queryParams.DAD069) {
      this.PROJID = this.activateroute.snapshot.queryParams.PROJID;
      this.DAD068 = this.activateroute.snapshot.queryParams.DAD068;
      this.DAD069 = this.activateroute.snapshot.queryParams.DAD069;
      this.DAD017 = this.activateroute.snapshot.queryParams.DAD017;
      this.YBSH_QUERY();
      this.YBCL_QUERY();
      this.params = { sname: 'ShFf_QUERY', form: { DAD069: this.DAD069 } };
    }
  }
  //打开情况下再次传入值
  _onReuseInit(): void {
    if (this.activateroute.snapshot.queryParams.DAD069) {
      this.PROJID = this.activateroute.snapshot.queryParams.PROJID;
      this.DAD068 = this.activateroute.snapshot.queryParams.DAD068;
      this.DAD069 = this.activateroute.snapshot.queryParams.DAD069;
      this.DAD017 = this.activateroute.snapshot.queryParams.DAD017;
      this.YBSH_QUERY();
      this.YBCL_QUERY();
      this.params = { sname: 'ShFf_QUERY', form: { DAD069: this.DAD069 } };
    }
  }
  //事项进度
  selectTab(str: string) {
    this.tabMode = str;
    if (str === 'sxjd') {
    }
  }
  // tslint:disable-next-line: use-lifecycle-interface
  ngAfterViewInit() {
    this.YBSH_QUERY();
    setTimeout(() => {
      this.YBCL_QUERY();
    }, 500);
  }

  //材料列表
  YBCL_QUERY() {
    this.lbservice
      .lbservice('YBCLSM_QUERY', {
        para: { PROJID: this.PROJID, FLAG: '2' },
      })
      .then(resdata => {
        if (resdata.code === 0) {
          this.msgSrv.error(resdata.errmsg);
        } else {
          this.dataset = resdata.message.list;
        }
      });
  }

  //审核档案信息
  YBSH_QUERY() {
    this.lbservice
      .lbservice('YBSH_QUERY', { para: { DAD069: this.DAD069 } })
      .then(resdata => {
        if (resdata.code < 1) {
          this.msgSrv.error(resdata.errmsg);
        } else {
          this.sf.formData = resdata.message.list[0];
          this.sf.reset();
        }
      });
  }

  //待遇审核
  SH_insert() {
    this.lbservice
      .lbservice('SH_insert', {
        para: {
          AAE000: this.AAE000,
          AIC200: this.AIC200,
          sf: this.sf.value,
          slxx: this.slxx.value,
        },
      })
      .then(resdata => {
        if (resdata.code < 1) {
          this.msgSrv.error(resdata.errmsg);
        } else {
          this.msgSrv.info('审核成功');
          this.isVisible = true;
          this.sf.formData = null;
          this.slxx.formData = null;
          this.slxx.reset();
          this.sf.reset();
        }
      });
  }
  //是否打印页面
  handleOk(): void {
    this.isOkLoading = true;
    this.print();
    setTimeout(() => {
      this.isVisible = false;
      this.isOkLoading = false;
    }, 3000);
  }
  handleCancel(): void {
    this.isVisible = false;
  }
  //打印功能
  print() {
    const modal = this.modalService.create({
      nzTitle: '打印',
      nzContent: LbRepComponent,
      nzComponentParams: {
        repid: '50',
        inpara: { DAD069: this.DAD069 },
      },
      nzWidth: 880,
    });
  }

  open(recode: any) {
    if (recode.ATTACHPATH !== '无') {
      window.open(recode.ATTACHPATH);
    } else {
      alert('不存在文件地址');
    }
  }

  // tslint:disable-next-line:all
  pname = '待遇信息';
  // tslint:disable-next-line: member-ordering
  active = true;
  // tslint:disable-next-line: member-ordering
  pname1 = '发放信息';
  // tslint:disable-next-line: member-ordering
  active1 = true;
  // tslint:disable-next-line: member-ordering
  icon1 = 'caret-right';
}
